<?php

namespace app\home\middleware;

use app\customer\BizResponse;
use app\consts\Code;
use app\consts\Keywords;
use Webman\Http\Request;
use Webman\Http\Response;
use Webman\MiddlewareInterface;

class LoginCheck implements MiddlewareInterface
{
    use BizResponse;
    public function process(Request $request, callable $next) : Response
    {
        //如果用户没有登录就返回
        if($request->{Keywords::USER_ID} == null  || $request->{Keywords::USER_ID} < 0) {
            return $this->error(Code::LOGIN_REQUIRED);
        }

        $response = $next($request);

        return $response;
    }
}